import Mock from 'mockjs';

Mock.mock('/api/getProduct', 'get', {
  '_id|+1':1,
  id: "@natural(10,20)",
  name: "@word()",
  cname: "@cname()",
  title:"@ctitle(6)",
  price: "@float(10,100)",
  //Random.image('200x100', '#ffcc33', '#FFF', 'png', '!')
  img: "@image('200x100', '#ffcc33', '#FFF', 'png', 'gp18')"
})


Mock.mock(/\/api\/getProductById\//, 'get', (options) => {

  console.log(options);
  let result = /\/api\/getProductById\/(\d+)/.exec(options.url);
  return Mock.mock({
    id: result[1],
    name: "@word()"
  })
})

Mock.mock('/api/getProductlist','get',()=>{
  return Mock.mock({
    code:1,
    "data|3-10":[{
      id:"@natural(10,20)",
      name:"@word()"
    }]
  })
})

Mock.mock('/api/addProduct','post',(options)=>{
  console.log(options);
  return Mock.mock({
    code:1,
    message:"添加产品成功"
  })
})

